/*
    pthread_t pid;这个pid到底是什么？
    create new thread tid: %lu\n   ：  create new thread tid: 140033414510336
    create new thread tid: %p\n    :   create new thread tid: 0x7f8a5e7ea700
    
*/

#include <iostream>
#include <pthread.h>
#include <unistd.h>
#include <string>

using namespace std;

int g_val = 100;

// new thread
void* threadRoutine(void* args)
{
    const char* name = (const char*)args;
    while(true)
    {
        // printf("new thread pid: %d, g_val: %d, &g_val: %p\n", getpid(), g_val, &g_val);
        printf("%s, %d, g_val: %d, &g_val: %p\n", name, getpid(), g_val, &g_val);
        // cout << "new thread, pid: " << getpid() << endl;
        sleep(1);
    }
}

int main()
{
    pthread_t pid;
    pthread_create(&pid, nullptr, threadRoutine, (void*)"thread 1");  

    while(true)
    {
        printf("main thread pid: %d, g_val: %d, &g_val: %p, create new thread tid: %p\n", getpid(), g_val, &g_val, pid);
        // cout << "main thread, pid: " << getpid() << endl;
        sleep(1);
    }
    return 0;
}